<!doctype html>
<html lang="en">
<head>
    <meta charset="UTF-8" />
    <title>企业查询</title>
    <meta name="viewport" content="width=device-width,initial-scale=1,minimum-scale=1,maximum-scale=1,user-scalable=no" />
    <include file="Public:iframe_header"/>
    <style type="text/css">

* {
    font-size: 95%;
    font-family: haettenschweiler;
}

html
 {
    height: 100%;
    padding: 0;
    margin: 0;
    background-color: #fff;
   
}
body{
    padding: 0;
    margin: 0;
    background-color: #fff;
}
button{
    background-color: orange;
}

.tab-page{
    width: 100%;
    margin: 10px auto;
    text-align: center;
}
.tab-page a{
    padding: 2px 8px;
    border: 1px solid #C8C7CC;
}

.a-page{
    background-color: blue;
    color: white;
}
.qy-cont {

    background-color: white;
    width: 100%;
}
.qy-tab{
    width: 100%;
    height:calc(60% - 60px);
    
    overflow-y: scroll;
    
}

.div-jz{
    text-align: center;
    margin-top:10px;
}

.div-jz button{
    text-align: center;
    border: 1px solid #F4F4F4;
    color: #C8C7CC;
    background-color: #F4F4F4;
}

.btn3{
    /*background-color:#00B1D7*/
}
input{
    -webkit-user-select:auto;
}

    </style>
</head>
<body>
<div class="mui-content" style="background-color: #fff;">
    <div class="img_path" style="position: relative;">
        <div class="h-img" id="img-id">
            <img src="__STATIC__/mobile/img/qy.png" width="100%" />
        </div>

        <div class="qy-cont" id="cont-id">
            <div id="" class="qy-cx">
                <div id="">
                    <b>查询筛选:</b>
                </div>
                <div id="">
                </div>
            </div>
            

            <div class="h-ss">
                <div class="h-qz">
                </div>
                <div class="h-inp">
                    <input placeholder="输入关键字查找..." name="sear_name" id="" value="" />
                </div>

                <div class="h-s-img">
                    搜索
                </div>
            </div>
        </div>
    </div>
    <table border="0" cellspacing="10" cellpadding="10" align="center" >
            <tr>
                <th class="h1">名称</th>
                <th class="t2">地址</th>
                <th class="t3">操作</th>
            </tr>
    </table>
    <div class="qy-tab" id="tab-id">
        <table id="table" border="0" cellspacing="10" cellpadding="10" align="center" >
            <volist name="xls_company" id="vo">
                <tr>
                    <td class="t1" _href="{$vo.url}" id="{$vo.id}" onclick="return_company(this)" verification_login="true">{$vo.name}</td>
                    <td class="t2" _href="{$vo.url}" id="{$vo.id}" onclick="return_company(this)" verification_login="true">{$vo.path_tem}</td>
                    <if condition="$vo.is_attention eq 0 || $vo.is_attention eq -1">
                        <td class="btn1" style="width: 25%;" onclick="change_class(this)" <if condition="$vo.is_attention eq -1">status="1"<else />status="0"</if>company_id="{$vo.id}"><button>关注</button></td>
                    </if>
                    <if condition="$vo.is_attention eq 1">
                        <td class="btn3" style="width: 25%;" onclick="change_class(this)"  status="-1" company_id="{$vo.id}"><button>取消关注</button></td>
                    </if>
                </tr>
            </volist>
        </table>
        <if condition="$click_for_more">
            <div id="click_for_more" class="div-jz" style="" page="1">
                <button>点击加载更多</button>
            </div>
        </if>
    </div>


</div>
<script>
    var mui_content = $('.mui-content').height();
    var img_path = $('.img_path').height();
    var total_height = mui_content - (img_path+85);
    //var body_height = $("body").height();

    //检测是否有权限
     function return_company(obj){
         var a_href = $(obj).attr('_href');
         var id = $(obj).attr('id');

         var formData = new FormData();
         formData.append('id',id);

         $.ajax({
             url:a_href,
             type:'POST',
             data:formData,
             async:true,
             processData:false,
             contentType:false,
             success:function(result){
                 if(result.code == 0){
                     parent.tips(result.msg);
                     return false;
                 }
                 window.location.href=result.url;
             }

         });
     }

    $('.h-s-img').click(function(){
        var sear_name_val = $('input[name="sear_name"]').val();
        var index = parent.wait();

        $.post("{:url('Company/zquery')}",{name:sear_name_val},function(result){
            var html = '';
            var data = result.msg.xls_company;

            for(var i=0;i<data.length;i++){
                html += '<tr>';
                html += '<td class="t1" verification_login="true" id="'+data[i].id+'" _href="'+data[i].url+'" onclick="return_company(this)">';
                html += data[i].name;
                html += '</td>';
                html += '<td class="t2" verification_login="true" id="'+data[i].id+'" _href="'+data[i].url+'" onclick="return_company(this)">'+data[i].path_tem+'</td>';
                if(data[i].is_attention == '0' || data[i].is_attention == '-1'){
                    html += '<td class="btn1" style="width: 25%;" onclick="change_class(this)"'; 
                    if(data[i].is_attention == '-1'){
                        html += 'status="1"';
                    }else{
                        html += 'status="0"';
                    } 
                    html += 'company_id="'+data[i].id+'"><button>关注</button></td>';
                }
                if(data[i].is_attention == '1'){
                    html += '<td class="btn3" style="width: 25%;" onclick="change_class(this)"  status="-1" company_id="'+data[i].id+'"><button>取消关注</button></td>';
                }
                html += '</tr>';
            }
            if(!result.msg.click_for_more){
                $("#click_for_more").find("button").remove();
            }else{
                var click_for_more = $("#click_for_more").find("button").length;
                if(click_for_more == 0){
                    $("#click_for_more").html("<button>点击加载更多</button>");
                }
            }

            $('#table').html(html);
            parent.close_wait(index);
        });
    });

    function change_class(obj){
        var status = $(obj).attr('status');
        var company_id = $(obj).attr('company_id');
        var class_name = $(obj).attr('class');
        var bool = false;

        var formData = new FormData();
        formData.append('status',status);
        formData.append('company_id',company_id);

        $.ajax({
            url:"{:url('Company/follow')}",
            type:'POST',
            data:formData,
            async:false,
            processData:false,
            contentType:false,
            success:function(result){
                if(result.code == 0){
                    parent.tips(result.msg);
                    bool = true;
                }
            }

        });

        if(bool){
            return false;
        }

        $(obj).removeClass('btn1');
        $(obj).removeClass('btn3');
        //$(obj).attr('status','');

        if(class_name == 'btn1'){
            $(obj).attr("class","btn3");
            $(obj).find('button').text("取消关注");
            $(obj).attr('status','-1');
        }else{
            $(obj).attr("class","btn1");
            $(obj).attr('status','1');
            $(obj).find('button').text("关注");
        }
    }

    $(function(){
        var height = document.documentElement.clientHeight;
        var head = $t("cont-id").offsetHeight;
        var ig = $t("img-id").offsetHeight;
        $("body").height(height + ig);
        $t("tab-id").style.height = (height - head ) + "px";
        var servar_name = $($(window.parent.document).find("iframe")[0]).attr("servar_name");
        
        if(typeof(servar_name) != 'undefined'){
            $("input[name='sear_name']").val(servar_name);
            $('.h-s-img').click();
        }   

        function $t(id) {
            return document.getElementById(id);
        }
    });

    $("#click_for_more").click(function(){
        var page=$(this).attr('page');
        page = parseInt(page);
        var sear_name_val = $('input[name="sear_name"]').val();
        page += 1;

        var formData = new FormData();
        formData.append('page',page);
        formData.append('name',sear_name_val);

        var index = parent.wait();

        $.ajax({
            url:"{:url('Company/ajax_page')}",
            type:'POST',
            data:formData,
            async:true,
            processData:false,
            contentType:false,
            success:function(result){
                if(result.msg.length == 0){
                    $("#click_for_more").remove();
                    return false;
                }else{
                    $("#click_for_more").attr('page',page);
                }

                var html = '';
                for(var i=0;i<result.msg.length;i++){
                    html += '<tr>';
                    html += '<td class="t1" verification_login="true" id="'+result.msg[i].id+'" _href="'+result.msg[i].url+'" onclick="return_company(this)">';
                    html += result.msg[i].name;
                    html += '</td>';
                    html += '<td class="t2" verification_login="true" id="'+result.msg[i].id+'" _href="'+result.msg[i].url+'" onclick="return_company(this)">'+result.msg[i].path_tem+'</td>';
                    if(result.msg[i].is_attention == '0' || result.msg[i].is_attention == '-1'){
                        html += '<td class="btn1" style="width: 25%;" onclick="change_class(this)"'; 
                        if(result.msg[i].is_attention == '-1'){
                            html += 'status="1"';
                        }else{
                            html += 'status="0"';
                        } 
                        html += 'company_id="'+result.msg[i].id+'"><button>关注</button></td>';
                    }
                    if(result.msg[i].is_attention == '1'){
                        html += '<td class="btn3" style="width: 25%;" onclick="change_class(this)"  status="-1" company_id="'+result.msg[i].id+'"><button>取消关注</button></td>';
                    }
                    html += '</tr>';
                }

                $('#table').append(html);
                parent.close_wait(index);
            }
        });

    });
   
</script>
</body>
</html>